<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>倒计时</title>
  </head>
  <body>
    <h1></h1>
  </body>
  <script>
    function getRTime() {
      var myh1 = document.querySelector("h1");
      var EndTime = new Date("2021/02/12 00:00:00");
      var NowTime = new Date();
      var t = EndTime.getTime() - NowTime.getTime(); // 过年时间 - 现在时间
      var d = Math.floor(t / 1000 / 60 / 60 / 24); //秒转天
      var h = Math.floor((t / 1000 / 60 / 60) % 24); //秒转小时
      var m = Math.floor((t / 1000 / 60) % 60); //秒转分
      var s = Math.floor((t / 1000) % 60); //秒
      var str = `距离过年还剩：${d}天${h}时${m}分${s}秒`;
      myh1.innerHTML = str;
    }
    setInterval(getRTime, 1000);
  </script>
</html>
